<?php
session_start();
include("../common/connect.php");
include("../common/common.php");

$opt = trim(CheckUrlParamNoDie("opt"));
$showtype = CheckUrlParamNoDie("showtype");
$tag = trim(CheckUrlParamNoDie("tag"));
$gid = trim(CheckUrlParamNoDie("gid"));
$uid = trim(CheckUrlParamNoDie("uid"));
$unm = trim(CheckUrlParamNoDie("unm"));
$nPage = CheckUrlParamNoDie("page");

if ($nPage == "") $nPage = 1;
if(isset($_POST["Site_Submit"]))
{
	$tdelivery = trim(GetPostParamStr("tdelivery"));
	$logistics = trim(GetPostParamStr("logistics"));
	$information = trim(GetPostParamStr("information"));
	
	$row = mysql_fetch_assoc(mysql_query("select user.id as uid, g.id as godid, g.dhtag as gtag, user.nick_name as name,g.dhtitle as gtitle from gwt_dh_order as o, gwt_dh_goods as g,user where user.id=$uid and user.id=o.user_id and o.goods_id=g.id limit 1"));
	$userid = $row["uid"];
	$nickname = $row["name"];
	$dhtitle = $row["gtitle"];
	$gtag = $row["gtag"];
	$godid = $row["godid"];
	//$tubi = $row["tubi"];
	
	if($gid != "")
	{
		mysql_query("update gwt_dh_order set delivery='$tdelivery', logistics='$logistics',ddzt=1, fhtime=now() where id=$gid");
		if($information == "")
		{
			mysql_query("insert into gwt_msg (touser,content,typexx) values (".$userid.",'亲爱的".$nickname."，您兑换的<font color=".'#0000FF'.">".$unm."</font>件商品<a href=".'../dh/index.php?catalog='."$gtag".'&gid='."$godid".''." target=".'_blank'." style=".'color:#FF0000'.">".$dhtitle."</a>已发货，您的运单号码为<b>".$tdelivery."</b>,物流公司为<b>".$logistics."</b>。请您注意查收！',2)");
		}else
		{
			mysql_query("insert into gwt_msg (touser,content,typexx) values (".$userid.",'亲爱的".$nickname."，您兑换的<font color=".'#0000FF'.">".$unm."</font>件商品<a href=".'../dh/index.php?catalog='."$gtag".'&gid='."$godid".''." target=".'_blank'." style=".'color:#FF0000'.">".$dhtitle."</a>已发货，".$information."。请您注意查收！',2)");
		}
		//if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-2);</script>";
	}
}

if ($opt == "del" && $gid != "")
{
	mysql_query("delete from gwt_dh_order where id=$gid");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}

$row = mysql_fetch_assoc(mysql_query("select count(*) as tmp from gwt_dh_order"));
$allCount = $row["tmp"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>订单管理-兑换商城中心管理</title>
<style type="text/css">
body {font-size: 12px;color: #000;font-family: 宋体;}
.STYLE1 {font-size: 13px;font-weight: bold;}
table {border-collapse:collapse; border-spacing:2px;  font-size:12px;}
td,th { display:table-cell; vertical-align:inherit;}
img { border:0; vertical-align:top;}
a { color:#00F;}
/***网站提交***/
.Unbound { background:#f2eeef; width:555px; padding:10px; position:absolute; top:10px; left:240px; font-size:12px;}
.Unbound .unss { background:#FFF; padding:10px; border:1px solid #999;}
.Unbound .sel { height:30px; border-bottom:1px solid #ddd;}
.Unbound .sel .Close a { float:right; text-indent:0; width:40px; display:inline-block;}
.Unbound .ted { overflow:hidden;}
.Unbound .ted .ted_tj { margin-top:10px; clear:both; overflow:hidden;}
.Unbound .ted .ted_tj span { width:90px; text-align:right; display:block; float:left;}
.Unbound .ted .ted_tj .tedinp,.Unbound .ted .ted_tj textarea { height:22px; line-height:22px; border:1px solid #ddd; font-size:12px; padding:0 5px; color:#666; overflow:hidden;}
.Unbound .ted .ted_tj select.tedinp { padding:0;}
.Unbound .ted .ted_tj textarea { width:360px; height:70px; }
.Unbound .ted .sz_btn { margin:20px auto; width:133px; overflow:hidden;}
.Unbound .ted .sz_btn input { background:url(http://www.gouwutu.com/new/doc/img/sebtn.jpg) no-repeat; cursor:pointer; padding:0; color:#FFF; font-weight:bold; width:133px; height:45px; border:0;}
/*********/
#pu_dht { margin:10px auto; text-align:center; width:100%;}
#pu_dht a,#pu_dht b { background-color:#F4D662; border:1px solid #F90; color:#fff; display:inline-block; font-size:12px; height:22px; line-height:22px; margin:0 1px; min-width:12px; padding:0 4px; white-space:nowrap; text-align:center;}
#pu_dht a { color:#F90; background-color:#FFF;}
#pu_dht a:hover {background-color:#F4D662;color:#fff;}
</style>
<script language="javascript">
function OnFind()
{
	var site_tag = document.getElementById("Site_Tag").value;
	var input_tradeid = document.getElementById("showtype").value;
	window.location.href= "order.php?showtype=" + input_tradeid + "&tag=" + site_tag ;
}
function sunbmintSS()
{
	var tdelivery = document.getElementById("tdelivery").value;
	var logistics = document.getElementById("logistics").value;
	
	if (tdelivery == "" && logistics == "")
	{
		alert("你丫的，靠！物流编号跟物流公司你都没有填写,你赶着去死啊~~!!~");
     	return false;
     }
	 
	return true;
}
</script>
</head>
<body>
<div style="">
<table width="100%" border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="#a8a8a8">
	<tr>
    	<td height="40" align="center" colspan="16"><font size="+2">兑换商城管理中心</font>订单信息管理</td>    
    </tr>
    <tr height="30" align="center" bgcolor="#00FF99">
    	<td colspan="16"><a href="dhcenter.php">商品信息管理</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="order.php" style="color:#F00">订单信息管理</a></td>
    </tr>
    <tr>
    	<td height="30" colspan="16">&nbsp;&nbsp;&nbsp;&nbsp;
        	<select  class="tedinp" name="Site_Tag" id="Site_Tag" size="1">
            	<option value="1" selected='selected'>订单号</option>
          		<option value="2">商品编码</option>
          		<option value="3">用户ID</option>
          		<option value="4">物流编号</option>
        	</select>&nbsp;&nbsp;
        	<input type="text" size="20" id="showtype" name="showtype" value="">&nbsp;&nbsp;
            <input type="button" value="查找" onclick="javascript:OnFind();">&nbsp;&nbsp;<a href="order.php">默认显示</a>&nbsp;&nbsp;<font color="#FF0000"> 0：<a href="">未发货</a> 1：<a href="">已发货</a> 3:<a href="">交易成功</a></font>
     	</td>
    </tr>
    <tr align="center" bgcolor="#66CCFF">
    	<td height="30">订单号</td>
    	<td  width="60" height="30">商品编码</td>
        <td>用户ID</td>
        <td width="30">数量</td>
        <td width="60">兔币</td>
        <td width="200">地址</td>
        <td width="60">姓名</td>
        <td width="70">联系方式</td>
        <td width="50">邮编</td>
        <td width="100">备注</td>
        <td>订单时间</td>
        <td width="100">物流编号</td>
        <td width="100">物流公司</td>
        <td>状态</td>
        <td>发货时间</td>
        <td width="100">操作</td>
    </tr>
<?php
$sql="";
$PAGE_SIZE = 15; //每页数量
$limit = " limit ". ($nPage-1)*$PAGE_SIZE .",$PAGE_SIZE";

if($showtype != "" && $tag == "3")
	$sql .= " where id='$showtype'";
else if($showtype != "" && $tag == "1")
	$sql .= " where goods_id=$showtype";
else if($showtype != "" && $tag == "2")
	$sql .= " where user_id=$showtype";
else if($showtype != "" && $tag == "3")
	$sql .= " where delivery='$showtype'";

$sql = "select * from gwt_dh_order".$sql." order by id asc".$limit;
$result = mysql_query($sql);
$i = 0;
while( $result && $row = mysql_fetch_assoc($result))
{
?>
	<tr align="center">
    	<td><?php echo $row["id"]; ?></td>
        <td><a href="dhcenter.php?showtype=<?php echo $row["goods_id"]; ?>&tag=1" target="_blank"><?php echo $row["goods_id"]; ?></a></td>
        <td><?php echo $row["user_id"]; ?></td>
        <td><?php echo $row["buynum"]; ?></td>
        <td><?php echo $row["needtubi"]; ?></td>
        <td><?php echo $row["address"]; ?></td>
        <td><?php echo $row["dhname"]; ?></td>
        <td><?php echo $row["hdphone"]; ?></td>
        <td><?php echo $row["postcode"]; ?></td>
        <td><?php echo $row["remark"]; ?></td>
        <td><?php echo $row["dtime"]; ?></td>
        <td><?php echo $row["delivery"]; ?></td>
        <td><?php echo $row["logistics"]; ?></td>
        <td><?php echo $row["ddzt"]; ?></td>
        <td><?php echo $row["fhtime"]; ?></td>
        <td height="30"><a href="?opt=edit&gid=<?php echo $row["id"]; ?>&uid=<?php echo $row["user_id"]; ?>&unm=<?php echo $row["buynum"]; ?>">编辑</a>&nbsp;&nbsp;<a href="javascript:if(confirm('确实要删除吗?'))location='?opt=del&gid=<?php echo $row["id"]; ?>'">删除</a></td>
    </tr>
    <?php } ?>
    <tr>
    	<td colspan="16">
        	<div id="pu_dht">
            <?PHP if ($allCount > $PAGE_SIZE) { ?>
				<div id="Pager1">
				 <?php	
                    $all_page = ceil($allCount / $PAGE_SIZE);
                    if ($nPage > 1) echo "<a class='pageNext' href='?page=".($nPage-1)."'>上一页</a>";
                    
                    if($all_page<=12){				
                        for($i=1;$i<=$all_page;$i++){//数字分页
                            $Pageshow = ($i!=$nPage)?"<a href='?page=$i'>".($i)."</a>":"<b>".($i)."</b>";
                            echo $Pageshow;
                        }
                    }else{
                        for($i=1;$i<=12;$i++){//数字分页
                            $Pageshow = ($i!=$nPage)?"<a href='?page=$i'>".($i)."</a>":"<b>".($i)."</b>";
                            echo $Pageshow;
                        }
                    }
                    
                    if($nPage == 12 || $nPage == $all_page){
                        echo "";
                    }else if($nPage < 12){
                        echo "<a class='pageNext' href='?page=".($nPage+1)."'>下一页</a>";
                    }
                     ?>
                </div>
            <?php
			}
			?>                          
        	</div>
        </td>
    </tr>
</table>
<?php	
if( $gid != "" && $opt=='edit' )
{
?>
<div style="display:block;" class="Unbound">
    <div class="unss">
        <div class="sel"><h2><span class="Close"><a href="order.php">关闭</a></span>编辑/添加</h2></div>
        <div class="ted">
            <form onsubmit="return sunbmintSS()" method="post" action="order.php?gid=<?php echo $gid; ?>&uid=<?php echo $uid; ?>&unm=<?php echo $unm; ?>">
                <div class="ted_tj"><span>物流编号：</span><input type="text" value="" name="tdelivery" id="tdelivery" maxlength="100" style="width:360px;" class="tedinp"></div>
                <div class="ted_tj"><span>物流公司：</span><input type="text" value="" name="logistics" id="logistics" maxlength="100" style="width:360px;" class="tedinp"></div>
                <div class="ted_tj"><span>消息：</span><textarea id="information" name="information" style=" width:359px; height:60px; overflow:hidden; font-size:12px;"></textarea></div>
                <p class="sz_btn"><input type="submit" value="提 交" name="Site_Submit" id="Site_Submit"></p>
                <span><!-----奇怪的360 去掉设置就没有了------></span>
            </form>
        </div>
    </div>
</div>
<?php } ?>
</div>
</body>
</html>
